package org.summerframework.component.quartz;

import org.summerframework.component.enums.annotation.EnumKind;
import org.summerframework.core.base.dto.BaseEnum;
import lombok.Getter;
import org.quartz.Trigger.TriggerState;

/**
 * @author 石超
 * @version v1.0.0
 */
@Getter
@EnumKind("QUART_STATE")
public enum QuartzStateEnum implements BaseEnum {
    NONE(-1, "不存在", TriggerState.NONE),
    NORMAL(0, "运行", TriggerState.NORMAL),
    PAUSED(1, "暂停", TriggerState.PAUSED),
    COMPLETE(2, "完成", TriggerState.COMPLETE),
    ERROR(3, "异常", TriggerState.ERROR),
    BLOCKED(4, "堵塞", TriggerState.BLOCKED),
    ;

    private Integer code;

    private String desc;

    private TriggerState state;

    public static QuartzStateEnum getInstance(Integer code) {
        if (code == null) return NONE;
        for (QuartzStateEnum statusEnum : QuartzStateEnum.values()) {
            if (statusEnum.getCode().equals(code)) {
                return statusEnum;
            }
        }

        return NONE;
    }

    @Override
    public boolean isType(Integer code) {
        return this.code.equals(code);
    }

    public boolean isState(TriggerState state) {
        return this.state.equals(state);
    }

    QuartzStateEnum(Integer code, String desc, TriggerState state) {
        this.code = code;
        this.desc = desc;
        this.state = state;
    }
}

